<?php

namespace App\Models\Agenda;

use App\Consts\BaseConsts\BaseConsts;
use App\Consts\TableConsts\TableConsts;
use App\Func\AgendaFunc;
use App\Models\BaseModel;


class AgendaModel extends BaseModel
{
    protected $table = TableConsts::CY_AGENDA;

    protected $fillable = [];

    public function addAgenda($data){
        return $this->insertGetId($data);
    }

    public function getAgendaList($query, mixed $pageSize)
    {
        return $query->where('status',BaseConsts::STATUS_NORMAL)
            ->latest()
            ->Paginate($pageSize);
    }

    public function getAgendaTypeStrAttribute($value): string{
        return AgendaFunc::getAgendaTypeStr($value);
    }

    public function editAgendaStatusBySourceAndType($sourceId,$type){
        return $this->where('agenda_source_id',$sourceId)->where('agenda_type',$type)->update(['status'=>2]);
    }

    public function editAgendaStatusBySourceAndTypeAndStaff($sourceId,$type,$staffId){
        return $this->where('staff_id',$staffId)->where('agenda_source_id',$sourceId)->where('agenda_type',$type)->update(['status'=>2]);
    }

    # 已完成是2 默认是1 未完成
    public function getAgendaStatusBySourceAndTypeNoStatusCount($sourceId,$type){
        return $this->where('agenda_source_id',$sourceId)->whereIn('agenda_type',$type)->where('status',1)->count();
    }

    public function getAgendaStatusBySourceAndTypeOkStatusCount($sourceId,$type){
        return $this->where('agenda_source_id',$sourceId)->whereIn('agenda_type',$type)->where('status',2)->count();
    }

    public function getAgendaStatusBySourceAndTypeStatusCount($sourceId,$type){
        return $this->where('agenda_source_id',$sourceId)->whereIn('agenda_type',$type)->count();
    }
}